package cn.gzsf.coolshark.controller;

import cn.gzsf.coolshark.entity.User;
import cn.gzsf.coolshark.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/login")
    public int login(@RequestBody  User user){
        //根据用户名从数据库查用户信息
        User u = userMapper.getUserByUsername(user.getUsername());
        if(u==null){//没有查到用户信息，返回3
            return 3;
        }
        if(u.getPassword().equals(user.getPassword())){//密码对上了，返回1，登录成功
            return 1;
        }
        return 2;//用户名对上，但是密码不对
    }
}
